package pervasivePositioning.pos;
import android.location.Location;

public class PeriodicStrategy extends ReportingStrategy {
	long delay = 1000;
	Location lastFix;
	
	public void setValue(float sec) {
		if (sec > 0)
			delay = (long) (sec * 1000);
	}

	public PeriodicStrategy() {
	}

	public PeriodicStrategy(long msec) {
		setValue(msec);
	}
	
	@Override
	public boolean reportPosition(Location newloc) {
		if(lastFix == null)
			return true;
		
		long time = newloc.getTime();
		if (time < lastFix.getTime() + delay) {
			return false;
		}
		lastFix = newloc;
		return true;
	}

	@Override
	public String getName() {
		return "PeriodicStrategy";
	}

	@Override
	public String getConfig() {
		// TODO Auto-generated method stub
		return String.valueOf(delay);
	}

	@Override
	public float getValue() {
		return (float) (delay/1000);		
	}

	@Override
	public String getValueName() {
		// TODO Auto-generated method stub
		return "delay";
	}
}
